package com.library.service;

import com.library.dao.ReaderDAO;
import com.library.model.Reader;

import java.util.List;

public class ReaderService {
    private ReaderDAO readerDAO = new ReaderDAO();

    public List<Reader> getAllReaders() {
        return readerDAO.getAllReaders();
    }

    public boolean addReader(Reader reader) {
        try {
            return readerDAO.insert(reader);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public boolean updateReader(Reader reader) {
        try {
            return readerDAO.update(reader);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public boolean deleteReader(String readerNumber) {
        return readerDAO.delete(readerNumber);
    }

    // 新增的方法，用于根据读者编号获取读者信息
    public Reader getReaderByNumber(String readerNumber) {
        return readerDAO.getReaderByNumber(readerNumber);
    }
}